Repository navigation
gh-158973: Reset the warnings lock after fork in the child - #158974
Conversation
Add _PyRecursiveMutex_at_fork_reinit() helper function.
|
I was able to reproduce this independently and validate the fix. With a probe similar to
I saw the same on AWS Lambda (x86_64, PGO+LTO build), where this matters since the default runtime is a regular GIL build: every attempt hit the watchdog before the fix, and none did after it. |
|
I think it's safe to store the bool in a static global: https://github.com/nascheme/cpython/compare/gh-158973-reset-warnings-lock...ngoldbaum:cpython:gh-158973-reset-warnings-lock?expand=1 This is being maximally cautions about avoiding ABI changes where they're not needed. I'm not sure if it's actually a problem in-practice. The static global is a bit of a code smell. |
ngoldbaum
left a comment
There was a problem hiding this comment.
I think this is good to merge for main but I'm not sure about the backport, see my comment.
|
Thanks @nascheme for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15. |
|
Sorry, @nascheme, I could not cleanly backport this to Please backport manually with cherry_picker, see the devguide for more information. |
|
GH-159613 is a backport of this pull request to the 3.15 branch. |
|
GH-159614 is a backport of this pull request to the 3.15 branch. |
|
GH-159615 is a backport of this pull request to the 3.14 branch. |
Reset the warnings lock in the child after fork, before clearing other threads’ states. This prevents deadlocks when their finalizers issue warnings and the lock was held by a thread that no longer exists. Record ownership before fork so the child can preserve the lock’s recursion depth and update its owner ID if the forking thread held it. Adds regression tests for child-cleanup warnings and recursive ownership across fork.
The PR was developed with assistance from GPT 6.1 Sol.
os.fork()child can hang insidePyOS_AfterFork_Child()on the warnings lock (3.14 regression) #158973